//
//  DYZMySourceDetailController.m
//  DYZCars
//
//  Created by MF on 16/8/20.
//  Copyright © 2016年 MF. All rights reserved.
//

#import "DYZMySourceDetailController.h"
#import "DYZMySourceInfo.h"
#import "DYZMySharedButtonController.h"
#import "UIColor+Addition.h"

@interface DYZMySourceDetailController ()
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *noLabel;
@property (weak, nonatomic) IBOutlet UILabel *dealPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *colorLabel;
@property (weak, nonatomic) IBOutlet UILabel *saleLabel;

@property (weak, nonatomic) IBOutlet UILabel *remarksLabel;

@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;

@property (nonatomic,assign) NSUInteger flag;
@property (nonatomic,weak) UIView *btnsView;
@end

@implementation DYZMySourceDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.typeLabel.text = self.sourceInfo.type;
    self.timeLabel.text = self.sourceInfo.time;
    self.priceLabel.text = self.sourceInfo.dealPrice;
    self.noLabel.text = self.sourceInfo.no;
    self.dealPriceLabel.text = self.sourceInfo.dealPrice;
    self.colorLabel.text = self.sourceInfo.color;
    self.saleLabel.text = self.sourceInfo.saleRegion;
    self.remarksLabel.text = self.sourceInfo.remarks;
    self.nameLabel.text = self.sourceInfo.master;
    self.phoneLabel.text = self.sourceInfo.phone;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:self.sourceInfo.photo]];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"u832"] style:UIBarButtonItemStylePlain target:self action:@selector(jumpShared)];
}

-(void)jumpShared{
    NSLog(@"123");
    if (!self.flag) {
        UIView * view = [[UIView alloc]init];
        view.backgroundColor = [UIColor blueColor];
        [[UIApplication sharedApplication].keyWindow addSubview:view];
        self.btnsView = view;
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_topLayoutGuideBottom);
            make.right.equalTo(self.view);
            make.width.offset(80);
            make.height.offset(180);
        }];
        UIButton *oneBtn = [[UIButton alloc]init];
        UIButton *twoBtn = [[UIButton alloc]init];
        UIButton *threeBtn = [[UIButton alloc]init];
        UIButton *fourBtn = [[UIButton alloc]init];
        [oneBtn setBackgroundColor:[UIColor colorWithHex:0x4da8fc]];
        [twoBtn setBackgroundColor:[UIColor colorWithHex:0x4da8fc]];
        [threeBtn setBackgroundColor:[UIColor colorWithHex:0x4da8fc]];
        [fourBtn setBackgroundColor:[UIColor colorWithHex:0x4da8fc]];
        [oneBtn setTitle:@"收藏" forState:UIControlStateNormal];
        [twoBtn setTitle:@"分享" forState:UIControlStateNormal];
        [threeBtn setTitle:@"退定金" forState:UIControlStateNormal];
        [fourBtn setTitle:@"成交" forState:UIControlStateNormal];
        [view addSubview:oneBtn];
        [view addSubview:twoBtn];
        [view addSubview:threeBtn];
        [view addSubview:fourBtn];
        NSArray *btnArr = @[oneBtn,twoBtn,threeBtn,fourBtn];
        for (int i = 0 ; i < btnArr.count; i++) {
            UIButton *btn = btnArr[i];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
        }
        [oneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(view);
            make.height.offset(45);
        }];
        [twoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(oneBtn.mas_bottom);
            make.left.right.equalTo(view);
            make.height.equalTo(oneBtn);
        }];
        [threeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(twoBtn.mas_bottom);
            make.left.right.equalTo(view);
            make.height.equalTo(twoBtn);
        }];
        [fourBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(threeBtn.mas_bottom);
            make.left.right.equalTo(view);
            make.height.equalTo(threeBtn);
        }];
        //分享按钮的事件
        [twoBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
        self.flag = 1;
        
    }else{
        [self.btnsView removeFromSuperview];
        self.flag = 0;
    }
}
-(void)shareClick:(UIButton *)sender{
    DYZMySharedButtonController * shareVC = [[DYZMySharedButtonController alloc]init];
    
    self.definesPresentationContext = YES; //self is presenting view controller
    shareVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
    shareVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    
    [self presentViewController:shareVC animated:YES completion:nil];
    
}


@end
